﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;
using IBLL;
using Factory;
using System.Linq.Expressions;

namespace BLL
{
    public class BaseService<T> where T:class,new()
    {
        //public IBaseDAO<T> dao { get; set; }
        protected IBaseDAO<T> dao = SessionFactory.CreateDAO<IBaseDAO<T>>();
        public bool Add(T entity)
        {
            dao.Add(entity);
            return SessionFactory.SaveChanges() > 0;
        }
        public bool Delete(T entity)
        {
            dao.Delete(entity);
            return SessionFactory.SaveChanges() > 0;
        }
        public bool Update(T entity)
        {
            dao.Update(entity);
            return SessionFactory.SaveChanges() > 0;
        }
        public List<T> GetList(Func<T, bool> where)
        {
            return dao.GetList(where);
        }
        public List<T> GetListByPage<S>(Func<T, bool> where, Func<T, S> order, bool isAsc, int pageIndex, int pageSize, ref int count)
        {
            return dao.GetListByPageIndex(where,order,isAsc,pageIndex,pageSize,ref count);
        }
        
        public List<T> GetListByPageIndexBy<S>(Expression<Func<T, bool>> where, Func<T, S> lambadaOrder, bool isAsc, int pageIndex, int pageSize, out int count)
        {
            return dao.GetListByPageIndexBy(where, lambadaOrder, isAsc, pageIndex, pageSize, out count);
        }
        
    }
}
